|
|
9.2 | Internet Addresses | ||
| 9.2.2 | Decimal and binary conversion |
|
There are many ways to solve a problem.
There are also several ways to convert decimal numbers to binary
numbers. One method is presented here, however it is not the only
method. The student may find other methods easier. It is a matter of
personal preference.
When converting a decimal number to
binary, the biggest power of two that will fit into the decimal
number must be determined.
Since working with computers often is
referenced by bytes it is easiest to start with byte boundaries and
calculate from there.
The second example is 104. Since this
number is less than 255, it can be represented by one byte. The binary
equivalent of 104 is 01101000.
This method works for any decimal number. Consider the decimal number one million. Since one million is greater than the largest value that can be held in two bytes, 65535, at least three bytes will be needed. By multiplying by two until 24 bits, three bytes, is reached, the value will be 8,388,608. This means that the largest value that 24 bits can hold is 16,777,215. So starting at the 24-bit, follow the process until zero is reached. Continuing with the procedure described, it is determined that the decimal number one million is equal to the binary number 00001111 01000010 01000000. Figure
Binary to decimal conversion is just
the opposite. Simply place the binary in the table and if there is a
one in a column position add that value into the total.
Figure
|